package series

import (
	"fmt"
	"errors"
)

func init(){
	fmt.Println("init1")
}

func init(){
	fmt.Println("init2")
}

var errorLessThenTwo = errors.New("n range shoud in [2,10]")
var errorLargerThenTen = errors.New("n larger then 10")

// GetFibonacci fib func.
func GetFibonacci(n int) ([]int, error) {
	//及早失败，避免嵌套
	if n < 2 {
		return nil, errorLessThenTwo
	}
	if n > 10 {
		return nil, errorLargerThenTen
	}
	fibList := []int{1, 1}
	for i := 2; /*短变量生命*/ i < n; i++ {
		fibList = append(fibList, fibList[i-2]+fibList[i-1])
	}
	return fibList, nil
}
